package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Description NursingLevelServiceImpl
 * @Author lizhiwen
 * @Date 2024-09-10
 */
@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    @Override
    public List<NursingLevelVo> findAll() {
        List<NursingLevelVo> list = nursingLevelMapper.findAll();

        return list;
    }

    @Override
    public void insert(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevel.setCreateBy(1L);
        nursingLevel.setCreateTime(LocalDateTime.now());
        nursingLevelMapper.insert(nursingLevel);


    }

    @Override
    public PageResponse<NursingLevelVo> page(Integer pageNum, Integer pageSize, String name, Integer status) {
        PageHelper.startPage(pageNum, pageSize);

        Page<NursingLevel> page = nursingLevelMapper.page(name, status);

        PageResponse<NursingLevelVo> of = PageResponse.of(page, NursingLevelVo.class);

        return of;

    }

    @Override
    public void update(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.update(nursingLevel);
    }

    @Override
    public NursingLevelVo findById(Integer id) {
        NursingLevel nursingLevel = nursingLevelMapper.findById(id);
        NursingLevelVo nursingLevelVo = BeanUtil.toBean(nursingLevel, NursingLevelVo.class);

        return nursingLevelVo;
    }

    @Override
    public void deleteById(Integer id) {
        nursingLevelMapper.deleteById(id);
    }

    @Override
    public void setStatus(Integer id, Integer status) {
        nursingLevelMapper.setStatus(id, status);
    }
}
